From 028afee0e10af22219efd601ea4016c77324af55 Mon Sep 17 00:00:00 2001 From: Boris Ostrovsky Date: Fri, 23 Jan 2015 17:50:53 +0100 Subject: [PATCH] x86/VPMU: manage VPMU_CONTEXT_SAVE flag in vpmu_save_force() There is a possibility that we set VPMU_CONTEXT_SAVE on VPMU context in vpmu_load() and never clear it (because vpmu_save_force() will see VPMU_CONTEXT_LOADED bit clear, which is possible on AMD processors) The problem is that amd_vpmu_save() assumes that if VPMU_CONTEXT_SAVE is set then (1) we need to save counters and (2) we don't need to "stop" control registers since they must have been stopped earlier. The latter may cause all sorts of problem (like counters still running in a wrong guest and hypervisor sending to that guest unexpected PMU interrupts). Since setting this flag is currently always done prior to calling vpmu_save_force() let's both set and clear it there. Signed-off-by: Boris Ostrovsky Reviewed-by: Konrad Rzeszutek Wilk Reviewed-by: Dietmar Hahn Tested-by: Dietmar Hahn --- xen/arch/x86/hvm/vpmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/hvm/vpmu.c b/xen/arch/x86/hvm/vpmu.c index efb2279163..e17e19459c 100644 --- a/xen/arch/x86/hvm/vpmu.c +++ b/xen/arch/x86/hvm/vpmu.c @@ -128,6 +128,8 @@ static void vpmu_save_force(void *arg) if ( !vpmu_is_set(vpmu, VPMU_CONTEXT_LOADED) ) return; + vpmu_set(vpmu, VPMU_CONTEXT_SAVE); + if ( vpmu->arch_vpmu_ops ) (void)vpmu->arch_vpmu_ops->arch_vpmu_save(v); @@ -176,7 +178,6 @@ void vpmu_load(struct vcpu *v) */ if ( vpmu_is_set(vpmu, VPMU_CONTEXT_LOADED) ) { - vpmu_set(vpmu, VPMU_CONTEXT_SAVE); on_selected_cpus(cpumask_of(vpmu->last_pcpu), vpmu_save_force, (void *)v, 1); vpmu_reset(vpmu, VPMU_CONTEXT_LOADED); @@ -193,7 +194,6 @@ void vpmu_load(struct vcpu *v) vpmu = vcpu_vpmu(prev); /* Someone ran here before us */ - vpmu_set(vpmu, VPMU_CONTEXT_SAVE); vpmu_save_force(prev); vpmu_reset(vpmu, VPMU_CONTEXT_LOADED); -- 2.30.2